package com.ourfox.erp.init;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.http.HttpServlet;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.ourfox.platform.main.PlatformCore;

/**
 * 
 * <p>Title: SysListener.java</p>
 * <p>Description: 主要是初使化项目</p>
 * <p>Company: ourfox</p>
 *
 * @author luoxiujin<xiujin.luo@gmail.com>  
 * @version V1.0
 * @date 2011-10-10 下午8:27:25
 *
 */
public class SysListener extends HttpServlet implements ServletContextListener{


	private static final long serialVersionUID = 471292776346166052L;

	private static final Log LOGGER = LogFactory.getLog(SysListener.class);
	
	public void contextDestroyed(ServletContextEvent servletContextEvent) {
		// TODO Auto-generated method stub
		
	}

	public void contextInitialized(ServletContextEvent servletContextEvent) {
		
		String webRootpath = servletContextEvent.getServletContext().getRealPath("/");
		webRootpath = webRootpath.replace("\\\\", "/").replace("\\", "/");
		
		if(!webRootpath.endsWith("/")){
			webRootpath = webRootpath + "/";
		}
		
		if(LOGGER.isInfoEnabled()){
			LOGGER.info("Run Path: " + webRootpath);
		}
		
		PlatformCore.getInstance().getSystemInfo().setWebRootPath(webRootpath);
		
		String contextPath = servletContextEvent.getServletContext().getContextPath();
		
		if(LOGGER.isInfoEnabled()){
			LOGGER.info("Context Path: " + contextPath);
		}
		
		PlatformCore.getInstance().getSystemInfo().setContextPath(contextPath);
	}


}
